package game.entity;

import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;

import java.util.ArrayList;
import java.util.List;

/**
 * @date 2023/1/22 下午8:44
 */
public class Bomb extends AbstractEntity {


    private int imageIndex;

    private int fireFrame;

    private List<Image> bombs = new ArrayList<>();

    private List<Image> fire = new ArrayList<>();

    public Bomb(int x, int y, char c) {
        super(x, y, c);
        broken = true;
        bombs.add(new Image("file:src/game/image/bomb1.png"));
        bombs.add(new Image("file:src/game/image/bomb2.png"));
        bombs.add(new Image("file:src/game/image/bomb3.png"));
        bombs.add(new Image("file:src/game/image/bomb4.png"));
        bombs.add(new Image("file:src/game/image/bomb5.png"));
        bombs.add(new Image("file:src/game/image/bomb6.png"));
        bombs.add(new Image("file:src/game/image/bomb7.png"));
        bombs.add(new Image("file:src/game/image/bomb8.png"));

        fire.add(new Image("file:src/game/image/centre.png"));
        fire.add(new Image("file:src/game/image/vertical.png"));
        fire.add(new Image("file:src/game/image/end_top.png"));
        fire.add(new Image("file:src/game/image/vertical.png"));
        fire.add(new Image("file:src/game/image/end_bottom.png"));
        fire.add(new Image("file:src/game/image/horizontal.png"));
        fire.add(new Image("file:src/game/image/end_left.png"));
        fire.add(new Image("file:src/game/image/horizontal.png"));
        fire.add(new Image("file:src/game/image/end_right.png"));

    }

    @Override
    public void draw(GraphicsContext g, int frame) {
        int value = frame % 2;
        if (value == 0) {
            if (imageIndex < 7) {
                imageIndex++;
                image = bombs.get(imageIndex);
                super.draw(g, frame);
            } else {
                if (fireFrame < 4) {
                    fireFrame++;
                    g.drawImage(fire.get(0), x, y);
                    g.drawImage(fire.get(1), x, y - 32);
                    g.drawImage(fire.get(2), x, y - 64);
                    g.drawImage(fire.get(3), x, y + 32);
                    g.drawImage(fire.get(4), x, y + 64);
                    g.drawImage(fire.get(5), x - 32, y);
                    g.drawImage(fire.get(6), x - 64, y);
                    g.drawImage(fire.get(7), x + 32, y);
                    g.drawImage(fire.get(8), x + 64, y);
                }

            }
        } else {
            if (fireFrame == 0) {
                super.draw(g, frame);
            }
        }
    }

    public boolean isDestroy() {
        return fireFrame >= 4;
    }

}
